home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / VGA-VUL2.ZIP / VULTURE.TXT < prev   
Encoding:
Text File  |  1995-06-17  |  9.9 KB  |  193 lines

  1.  
  2.       ╒═══════════════════════════════════════════════════════════════╗
  3.       │■                                                            ■ ║
  4.       │                                                               ║
  5.       │  █████████░                   ██░                             ║
  6.       │  ██░    ██░ ██░   ██░ ██████░ ██░     ████████░ ██░     ██░   ║
  7.       │  ██░    ██░ ██░   ██░   ██░   ██░     ██░   ██░ ██░     ██░   ║
  8.       │  ██░    ██░ ██░   ██░   ██░   ██░     ████████░ ██░     ██░   ║
  9.       │  ██░    ██░ ██░   ██░   ██░   ██░     ██░   ██░ ██░ ██░ ██░   ║
  10.       │  █████████░ ████████░   ██░   ██████░ ██░   ██░  ███░ ███░    ║
  11.       │                                                               ║
  12.       │                        T ∙ R ∙ I ∙ A ∙ D                      ║
  13.       │■                                                            ■ ║
  14.       └───────────────────────────────────────────────────────────────╜
  15.                                ╔══════════════╗
  16.                                ║ ∙ PRESENTS ∙ ║
  17.                                ╚══════════════╝
  18.  
  19.                          Palette tricks in assembler.
  20. ───────────────────────────────────────────────────────────────────────────────
  21.  Created By   : Vulture                  Total Files  : 7
  22.  File Type    : VGA-intro source         Release Date : June 17th 1995
  23.  Difficulty   : Beginners level          Filename     : VGA-VUL2.ZIP
  24. ───────────────────────────────────────────────────────────────────────────────
  25.  
  26.  Well, here's another fine source-code by Vulture. This time I will cover the
  27.  palette. I have used a copple of these routines before (VGA-VUL1.ZIP) but I
  28.  thought it might be usefull to explain things in detail. As always the code
  29.  is documented but there are a few things that may need sum more explanation.
  30.  That is what I am gonna do in this file...
  31.  
  32.  The files included should be:
  33.  
  34.      - fade.exe       =>    The executable
  35.      - fade.asm       =>    The full source
  36.      - picture.dat    =>    Data for picture
  37.      - palette.dat    =>    Data for palette
  38.      - make.bat       =>    Makes the .exe
  39.      - vulture.txt    =>    This text (yeah:))
  40.      - file_id.diz    =>    File description
  41.  
  42.  Hmm, there probably are sum other files in here 2. Like bbs intros and stuff
  43.  like that... Never mind.
  44.  
  45.  Ok, here we go! The palette is what makes you see the colors you see. (wow:))
  46.  As you probably know, we have 256 colors in MCGA mode. These colors are made
  47.  by a combination of red, green and blue values. You just mix them together.
  48.  These R,G,B values can reach a maximum of 63. For example: 63,63,63 gives us
  49.  a white color and 0,0,0 gives us black. Logically 35,35,35 would give us a
  50.  gray color. You can create various colors using the palette. A maximum of
  51.  64*64*64=262144 combinations can be made. We choose 256 colors from these
  52.  262144 possibilities and we have a created full palette we can use in our
  53.  code. Wow, great huh? :)
  54.  
  55.  Well, let's say you have got a palette ready for use (like in a file). Then
  56.  you can use various techniques to set the palette. If you want to use it for
  57.  a picture, the simplest way to initialize it would be using the BIOS. Here
  58.  is the code to do that. Nothing to explain here... you are just using BIOS:
  59.  
  60.     mov     ax,cs            ; Move cs into AX
  61.     mov     es,ax            ; es points to cs (where data is located)
  62.     mov     ax,1012h         ; Select write palette function
  63.     mov     bx,0             ; Start at color 0
  64.     mov     cx,256           ; Write 256 colors ( 0-255 )
  65.     lea     dx,Palette       ; es:dx points to palette data
  66.     int     10h              ; Call VID interrupt & set palette
  67.  
  68.  Note that I use a label Palette here. You can ofcourse use your own labels.
  69.  Take a look at the source-code to see what I mean. I have used a file to
  70.  store all R,G,B values. Then I use the above routine to set the palette.
  71.  So, this is simple, eh? But only use this routine if you only want to show
  72.  a picture. It is very slow because you are using BIOS. And BIOS is slow....
  73.  If you want to rotate or fade the palette, you should use different methods.
  74.  Anyway, see the source for an example of the above method.
  75.  
  76.  Well, on to the next part. We can also use internal registers to set the
  77.  palette. This is more difficult to understand. Here we go...
  78.  Let's suppose you have created an array with all R,G,B values in it. That
  79.  would mean 256*3=768 values. Well, first we must have a pointer which points
  80.  to the start of the array. Do it like this:
  81.  
  82.     lea     bp,PaletteArray  ; Load offset array
  83.  
  84.  Ok, that's easy stuff, right? On to the real work. To write the palette we
  85.  have to use port 03c8h. This port was designed for writing the palette. We
  86.  use dx to set the port. We also have to choose the color we want to start
  87.  writing at. We use al to do that. Well, here's the code to do it:
  88.  
  89.     mov     dx,03c8h         ; Write register
  90.     mov     al,0             ; Start writing at color 0
  91.     out     dx,al            ; Give info to VGA
  92.  
  93.  This selects port 03c8h and tells the VGA that we want to start writing at
  94.  color 0. Still easy? Well, then we have to pass all R,G,B data to the VGA.
  95.  To do that we have to use port 03c9h. That's our data port. Now we simply
  96.  go into a loop where we set all R,G,B values at once. First we set cx to
  97.  768 because we want to set 768 values. Then set the port to 03c9h and go
  98.  into the loop. Inside the loop we increase the bp pointer to point to the
  99.  next cel. Here's the code:
  100.  
  101.     mov     cx,768           ; Do all values
  102.     mov     dx,03c9h         ; Data register
  103. WriteAll:
  104.     mov     al,byte ptr [bp] ; Get the value
  105.     out     dx,al            ; Write to VGA
  106.     inc     bp               ; Point to next cel
  107.     loop    WriteAll
  108.  
  109.  Well, this writes 768 values to the VGA. The total code for setting the
  110.  palette would now look like this:
  111.  
  112.     lea     bp,PaletteArray  ; Load offset array
  113.     mov     dx,03c8h         ; Write register
  114.     mov     al,0             ; Start writing at color 0
  115.     out     dx,al            ; Give info to VGA
  116.     mov     cx,768           ; Do all values
  117.     mov     dx,03c9h         ; Data register
  118. WriteAll:
  119.     mov     al,byte ptr [bp] ; Get the value
  120.     out     dx,al            ; Write to VGA
  121.     inc     bp               ; Point to next cel
  122.     loop    WriteAll
  123.  
  124.  Again, this code will set the palette values found in the PaletteArray using
  125.  the internal registers of the VGA. Fast stuff...
  126.  
  127.  Right. What if you want to READ the palette? Well, then you use port 03c7h.
  128.  This is our read-register. Instead of grabbing a value out of the array and
  129.  writing it to the VGA, you read it from the VGA and put it IN the array.
  130.  But there is one trick to do here. If you read from the VGA you must be sure
  131.  that you do not write values above 63 to the array. Remember that a palette
  132.  value can only be between 0 and 63. Take a look at the following code:
  133.  
  134.     in      al,dx            ; Get what's in the register (read)
  135.     and     al,00111111b     ; Mask of the upper 2 bits (value=0..63)
  136.  
  137.  Ok, I suggest you try to code your own read routine. Shouldn't be that hard
  138.  to do. Just modify the write routine I gave you here. If you have troubles,
  139.  just take a glance at the fully documented sourcecode provided.
  140.  
  141.  Keep in mind that there are indeed various otha ways to do this stuff. I
  142.  only explained the way I did it myself. I could have avoided a copple of
  143.  things but I decided to put it in there anyway. What's important is that
  144.  you fully understand those portwrites. The way you handle it from there
  145.  is totally up to you (hint: rep outsb).
  146.  
  147.  Well, I could ofcourse explain how the palettefading works but I let you
  148.  figure that one out for yourself. I just don't feel like explaning it... :)
  149.  Just play a little with the routines found here and you'll get the hang
  150.  of it soon. Only way to learn things is by trial and error, right?
  151.  
  152.  Ok, that's all I have to say for now. Check out the .asm file and learn from
  153.  it. Use it for yar own intros but don't just rip the code. Understand what
  154.  you are doing. Andeh... a greet would be appreciated. Simply ripping is lame.
  155.  But then again, if there weren't any lamerz, cewl people wouldn't have anyone
  156.  to loose their frustations on..... :)
  157.  
  158.  Hmm, well, the following cr*p is supposed to be stated so here we go:
  159.  I (Vulture) take no responsibility for any mistakes found in this document.
  160.  So use at your own risk. If you spot errors or have something to add to the
  161.  text, don't hesitate to contact me. Phew, that's that... :)
  162.  
  163.  Wanna contact Outlaw for any reason? Then leave mail at one of our distros.
  164.  Don't hestitate to mail Outlaw, coz we like to chat with otha scene-people.
  165.  
  166.  Be seeing ya...
  167.  
  168.  
  169.          Signed:    Vulture / Outlaw Triad
  170.  
  171.  
  172. ─────────────────────────┬───────────────────────┬────────────────────────────
  173.  Outlaw Triad Distros :  │  Greetz from Outlaw:  │  Releases sofar:
  174. ─────────────────────────┼───────────────────────┼────────────────────────────
  175.                          │                       │
  176.  ■    Blue Thunder   ■   │   - DemoLisher        │   ■ MESSAGE  (dosscroller)
  177.  ■ +31 (0)36-5346967 ■   │   - ThunderHawk       │
  178.                          │   - Ash               │   ■ VGA-VUL1 (sources)
  179.                          │   - The Machine       │
  180.  ■     FireHouse     ■   │   - X∙N∙TRiC          │   ■ CHAINDOC (textfile)
  181.  ■ +31 (0)58-2661590 ■   │   - Utter Chaos       │
  182.                          │   - Crusher           │   ■ VGA-VUL2 (sources)
  183.                          │                       │
  184.                          │   - Critical          │   ■ BASICDOC (textfile)
  185.      Open for more!      │   - Da Frisian Force  │
  186.                          │   - Tribal            │   + various bbs-intros
  187.                          │                       │
  188. ─────────────────────────┴───────────────────────┴────────────────────────────
  189.  
  190.                    ■ (C) 1995  O∙U∙T∙L∙A∙W   T∙R∙I∙A∙D ■
  191.  
  192. ──────────────────────────────────────────────────────────────────────────────
  193.